import axios from 'axios'

const api = axios.create({
  baseURL: '/api',
  timeout: 5000
})

// 请求拦截器，添加token
api.interceptors.request.use(
  config => {
    const token = localStorage.getItem('token')
    if (token) {
      config.headers.token = token
    }
    return config
  },
  error => {
    return Promise.reject(error)
  }
)

export const authApi = {
  // 登录
  login(data) {
    return api.post('/loginByJWT', data)
  },

  // 获取用户信息
  getUserInfo() {
    return api.get('/userinfo2')
  }
}

export default api
